<?php
class post_share { 
    var $ps_id;
    var $ps_p_id;
    var $ps_desc;
    var $ps_u_id;
    var $ps_date;
    var $ps_status;


    function Delete(){
        
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        $q = " select ps_status from post_share where ps_id ='".$this->ps_id."' " ;
        $rse = $DB->ObtenerData($q);   
        
        if($rse[0]["ps_status"]==0){
            $this->ps_status = 1;
        }else{
            $this->ps_status = 0;
        }
        
        $query = " UPDATE estado SET
                     ps_status='".$this->ps_status."'
                     where ps_id ='".$this->ps_id."' " ;
        
        $rs = $DB->EjecutarQuery($query);        
        $DB->DesconectarBD();        
        return $rs;  
    }

    function Update(){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        
        $query = " " ;
        
        $rs = $DB->EjecutarQuery($query);        
        $DB->DesconectarBD();        
        return $rs;  
    }

    function GetData(){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
         
        $query = " Select * from post_share where ps_id ='".$this->ps_id."' ";
        $rs = $DB->ObtenerData($query, "post_share" );

        $this->ps_id = $rs[0]["ps_id"];
        $this->ps_p_id = $rs[0]["ps_p_id"];
        $this->ps_desc = $rs[0]["ps_desc"];
        $this->ps_u_id = $rs[0]["ps_u_id"];
        $this->ps_date = $rs[0]["ps_date"];
        $this->ps_status = $rs[0]["ps_status"];

        $DB->DesconectarBD();        
    }

    function Save(){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        $query = " INSERT INTO post_share (
                     ps_id, ps_p_id, ps_desc, ps_u_id, ps_date, ps_status)
                    VALUES (NULL, '$this->ps_p_id', '$this->ps_desc', '$this->ps_u_id', '$this->ps_date', '$this->ps_status');" ;
        
        $rs = $DB->EjecutarQuery($query);        
        $DB->DesconectarBD();        
        return $rs;        
    }
    
    function GetList($vals = false, $orderby = false, $lim= false){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        
        if ($_REQUEST["seccion"] == "postshare" ) { //modulo post_share
        
            if(!isset($_REQUEST["li"])){
                $li = 0;
            }else{
                $li = $_REQUEST["li"];
            }               

            if(isset($_REQUEST["page"])){
                $li = ($_REQUEST["page"]* $_SESSION['PREF']['LIST_LIMIT'])- $_SESSION['PREF']['LIST_LIMIT'];
            }

            if(!$vals){
                $vals = " * ";            
            }

            if(!$lim){
                $limit ="LIMIT ".$li.", ".$_SESSION['PREF']['LIST_LIMIT']." ";
            }

            if($orderby){            
                $order =" ORDER BY $orderby ";
            }else{
                $order =" ORDER BY ps_status desc, ps_desc asc ";
            }

            if(isset($_REQUEST["estado"]) && $_REQUEST["estado"] <> 99 ){ 
                $where .= " and ps_status = ".$_REQUEST["estado"]."  ";
            }   

            if($_REQUEST["filtro"]){
                $query = " Select $vals from post_share where ps_desc like '%".$_REQUEST["filtro"]."%' $where
                                $order  $limit ";
            }else{
                $query = " Select $vals from post_share where 1=1 $where   $order  $limit   ";
            }
            
        } else {  //desde fuera del MODULO POST_SHARE
            
             $query = " Select $vals from post_share where ps_status = 1 $where  ";
            
        }
        
        $rs = $DB->ObtenerData($query, "post_share");

        if (trim($vals) != "count(*)"){

            foreach ($rs as $key => $val) {
                $p = new post_share();
                $p->set_ps_id($val["ps_id"]);
                $p->set_ps_p_id($val["ps_p_id"]);
                $p->set_ps_desc($val["ps_desc"]);
                $p->set_ps_u_id($val["ps_u_id"]);
                $p->set_ps_date($val["ps_date"]);
                $p->set_ps_status($val["ps_status"]);
                $rs2[] = $p;
            }

            $rs = $rs2;

            include_once 'recursos/funciones.php';
            $e = getEstado();        
            if(is_array($rs)){
                foreach ($rs as $key => $value) {
                    if ($value["ps_status"] == 1) {
                        $rs[$key]["ps_status"] = "<img src='images/png/estado_habilitado.png' />".$e[$value["ps_status"]];
                    } else {
                        $rs[$key]["ps_status"] = "<img src='images/png/estado_deshabilitado.png' />".$e[$value["ps_status"]];
                    }  
                }
            }
        }
        $DB->DesconectarBD();      
        return $rs;                
    }

    function get_ps_id(){
        return $this->ps_id;
    }
    function set_ps_id($val){
        $this->ps_id = $val;
    }

    function get_ps_p_id(){
        return $this->ps_p_id;
    }
    function set_ps_p_id($val){
        $this->ps_p_id = $val;
    }

    function get_ps_desc(){
        return $this->ps_desc;
    }
    function set_ps_desc($val){
        $this->ps_desc = $val;
    }

    function get_ps_u_id(){
        return $this->ps_u_id;
    }
    function set_ps_u_id($val){
        $this->ps_u_id = $val;
    }

    function get_ps_date(){
        return $this->ps_date;
    }
    function set_ps_date($val){
        $this->ps_date = $val;
    }

    function get_ps_status(){
        return $this->ps_status;
    }
    function set_ps_status($val){
        $this->ps_status = $val;
    }

}